from flask import Flask
from flask_wtf import FlaskForm
from flask_wtf.csrf import CSRFProtect
from wtforms import StringField,PasswordField,SubmitField,EmailField
from wtforms.validators import DataRequired, Length, EqualTo, Email


#创建 注册表单类--引入FlaskForm 类
class RegisterForm(FlaskForm):
    username = StringField('用户名',validators=[DataRequired(message='用户名不能为空'),Length(min=3,max=12,message='长度他应该为3~12个字符')])
    password = PasswordField('密码',validators=[DataRequired(message='密码不能为空'),Length(min=6,message='长度至少6位')])
    password2 = PasswordField('确认密码',validators=[DataRequired(message='密码不能为空'),EqualTo('password', message='两次密码不一致')])
    email = EmailField('邮箱', validators=[ Email(message='邮箱格式不正确')])
    submit = SubmitField('注册')
# 提供一个初始化CSRF的函数，由应用主程序调用
def init_csrf(app):
    """初始化CSRF保护，需传入已创建的app实例"""
    CSRFProtect(app)